/*
 * InsertPCB.c
 *
 *  Created on: Oct 2, 2013
 *      Author: Joseph DeLong
 */

#include <stdlib.h>
#include "mpx_pcb.h"
/*
 * INSERT PCB function
 * Written by Joseph DeLong
 * Debugged by Alex Newcomer
 */
void insertPCB(struct MPX_PCB *new, struct MPX_Q *r, struct MPX_Q *b) {
/*
	struct MPX_PCB temp;
	temp = findPCB((*new).processName, &r, &b); //look for this process in the queues
	if(temp == NULL) { //if no duplicate process was found, continue on
		if((*new).pcb_state != -1) { //if this PCB is NOT blocked
			if((*r).count > 0) { //if one or more PCBs are in ready queue
				 //get the first PCB
				for(temp = (*r).head; *temp; temp = (*temp).next) { //iterate through PCBs in READY queue
					if(((*temp).priority) >= ((*new).priority)) { //if new PCB has lower priority than current PCB in ready queue
						continue;
					}
					else if((temp->priority) < (new->priority)) { //if new PCB has higher priority than the current PCB in ready queue
						(*new).prev = (*temp).prev;
						(*new).next = (*(*temp).prev).next; //insert new PCB before current PCB
						(*(*temp).prev).next = new;
						(*(*temp).next).prev = new;
						(*temp).prev = NULL;
						(*temp).next = NULL;
						(*r).count++; //indicate addition of PCB into this queue
					}
				}
				if(temp == NULL) { //if traversed entire queue without inserting yet, put new PCB at the end
					(*new).prev = (*r).tail;
					(*(*r).tail).next = new;
					(*r).tail = new;
					(*r).count++; //indicate addition of PCB into this queue
				}
			}
			else {//READY QUEUE IS EMPTY
				(*r).head = new; //insert at HEAD of ready queue
				(*r).count++;  //indicate addition of PCB into this queue
			}
		}
		else { //new PCB IS blocked
			if((*b).count > 0) { //if one or more PCBs are in queue
				(*new).prev = (*b).tail; //insert at the tail of the blocked queue
				(*b).tail = new; //indicate new PCB as BLOCKED QUEUE's new tail
				(*b).count++;  //indicate addition of PCB into this queue
			}
			else { //BLOCKED QUEUE IS EMPTY
				(*b).head = new;//insert at HEAD of queue
				(*b).count++;  //indicate addition of PCB into this queue
			}
		}
	}
	*/
}
